package com.hboot.upms.config.beetl;

import com.hboot.core.util.ToolUtil;
import com.hboot.upms.common.config.HbootProperties;
import com.hboot.upms.web.util.KaptchaUtil;
import org.beetl.ext.spring.BeetlGroupUtilConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.ServerProperties;

import java.util.HashMap;
import java.util.Map;

public class BeetlConfiguration extends BeetlGroupUtilConfiguration {

    @Autowired
    private HbootProperties hbootProperties;

    @Autowired
    private ServerProperties serverProperties;

    @Override
    public void initOther() {
        groupTemplate.registerFunctionPackage("shiro", new ShiroExt());
        groupTemplate.registerFunctionPackage("tool", new ToolUtil());
        groupTemplate.registerFunctionPackage("kaptcha", new KaptchaUtil());
        Map<String, Object> extMap = new HashMap<>();
        extMap.put("staticUrl", (!"".equals(hbootProperties.getStaticUrl()) && hbootProperties.getStaticUrl() != null) ? hbootProperties.getStaticUrl() : serverProperties.getContextPath());
        groupTemplate.setSharedVars(extMap);
    }

}
